﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.ComponentModel;

    [ScriptType("SP.FieldLinkCollection", ServerTypeId="{6d87e76a-b8a8-4634-8170-082b1d454bfd}")]
    public class FieldLinkCollection : ClientObjectCollection<FieldLink>
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public FieldLinkCollection(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public FieldLink Add(FieldLinkCreationInformation parameters)
        {
            if (base.Context.ValidateOnClient)
            {
                if (parameters == null)
                {
                    throw ClientUtility.CreateArgumentNullException("parameters");
                }
                if ((parameters != null) && (parameters.Field == null))
                {
                    throw ClientUtility.CreateArgumentNullException("parameters.Field");
                }
            }
            FieldLink link = new FieldLink(base.Context, new ObjectPathMethod(base.Context, base.Path, "Add", new object[] { parameters }));
            link.Path.SetPendingReplace();
            ObjectIdentityQuery query = new ObjectIdentityQuery(link.Path);
            base.Context.AddQueryIdAndResultObject(query.Id, link);
            base.Context.AddQuery(query);
            base.AddChild(link);
            link.InitFromCreationInformation(parameters);
            return link;
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (flag)
            {
                return flag;
            }
            return flag;
        }
    }
}

